package com.lanju.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanju.model.ResultModel;
import com.lanju.service.OrganizationService;

@Controller
@RequestMapping("/organization")
public class OrganizationController {
    
    @Autowired
    OrganizationService organizationService;
    
    @RequestMapping("/addOrganization")
    @ResponseBody
    public ResultModel addOrganization(
            @RequestParam("name") String name,
            @RequestParam("managerCode") String managerCode){
        return organizationService.addOrganization(name,managerCode);
        
    }
    
    @RequestMapping("/editOrganization")
    @ResponseBody
    public ResultModel editOrganization(
            @RequestParam("id") int id,
            @RequestParam(value="name",required=false) String name,
            @RequestParam(value="managerCode",required=false) String managerCode){
        return organizationService.editOrganization(id,name,managerCode);
        
    }
    
    @RequestMapping("/delOrganization")
    @ResponseBody
    public ResultModel delOrganization(@RequestParam("id") int id){
        return organizationService.delOrganization(id);
        
    }
    
    @RequestMapping("/getOrganizationList")
    @ResponseBody
    public Map<String, Object> getOrganizationList(
            @RequestParam(value="name",required=false) String name,
            @RequestParam(value="managerCode",required=false) String managerCode,
            @RequestParam(value="offset") int offSet,
            @RequestParam(value="limit") int pageSize){
        return organizationService.getOrganizationList(name,managerCode,offSet,pageSize);
        
    }
    
    @RequestMapping("/getAllOrganizations")
    @ResponseBody
    public ResultModel getAllOrganizations(){
        return organizationService.getAllOrganizations();
        
    }

   
}
